package com.tadpole.music.view.activity.question;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.tadpole.music.R;
import com.tadpole.music.utils.Mutils;
import com.tadpole.music.utils.NoDoubleClickListener;
import com.tadpole.music.utils.ToastUtils;
import com.tadpole.music.view.activity.base.BaseActivity;

import java.io.SequenceInputStream;

/**
 * 调整设备
 * Created By 孙岩
 * on 2020/9/27
 */
public class EquipmentActivity extends BaseActivity {
    //回退
    private View view_back_icon;
    //标题
    private TextView actionbar_title;
    //content
    private TextView tvContent;
    //开始测试
    private TextView tvGO;
    //college_id
    private String college_id;
    //rank_id
    private String rank_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_equipment);
        college_id = getIntent().getStringExtra("college_id");
        rank_id = getIntent().getStringExtra("rank_id");
        initViews();
        initListeners();
        SpannableString spannable = new SpannableString("现在开始话筒和耳机测试，请按照下方的提示图， 戴好耳机，调整好话筒位置，准备好之后，请点“开始测试”按钮。");
        //这个一定要记得设置，不然点击不生效
        tvContent.setMovementMethod(LinkMovementMethod.getInstance());
        tvContent.setHighlightColor(Color.TRANSPARENT);
        //设置文字的前景色
        spannable.setSpan(getRedSpan(), 45, 50, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvContent.setText(spannable);
    }

    private ForegroundColorSpan getRedSpan() {
        return new ForegroundColorSpan(ContextCompat.getColor(this, R.color.color_red));
    }


    //初始化控件
    private void initViews() {
        view_back_icon = findViewById(R.id.view_back_icon);
        actionbar_title = findViewById(R.id.actionbar_title);
        actionbar_title.setText("调整设备");
        tvContent = findViewById(R.id.tvContent);
        tvGO = findViewById(R.id.tvGO);
    }

    //初始化监听器
    private void initListeners() {
        view_back_icon.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                EquipmentActivity.this.finish();
            }
        });

        tvGO.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                if (Mutils.isNetworkAvailable()) {
                    Intent intent = new Intent(EquipmentActivity.this, RealAnswerActivity.class);
                    intent.putExtra("college_id", college_id);
                    intent.putExtra("rank_id", rank_id);
                    startActivity(intent);
                } else {
                    ToastUtils.show("请检查您的网络设置");
                }
            }
        });
    }
}
